package com.yjy.fuyao.stu.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yjy.fuyao.stu.entity.Course;
import com.yjy.fuyao.stu.entity.Teacher;
import com.yjy.fuyao.stu.service.CourseService;
import com.yjy.fuyao.stu.service.TeacherService;
import com.yjy.fuyao.utils.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author yjy
 * @since 2021-08-12
 */
@Api(tags = "讲师管理")
//@CrossOrigin
@RestController
@RequestMapping("/front/stu/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    @Resource
    private CourseService courseService;

    @ApiOperation(value = "分页讲师列表")
    @GetMapping(value = "/list/{page}/{limit}")
    public R pageList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit){

        Page<Teacher> pageParam = new Page<Teacher>(page, limit);

        Map<String, Object> map = teacherService.pageListWeb(pageParam);

        return  R.ok().data(map);
    }


    @ApiOperation(value = "根据ID查询讲师")
    @GetMapping("/get/{id}")
    public R getById(
            @ApiParam(name = "id", value = "讲师ID", required = true)
            @PathVariable String id){

        //查询讲师信息
        Teacher teacher = teacherService.getById(id);

        //根据讲师id查询这个讲师的课程列表
        List<Course> courseList = courseService.selectByTeacherId(id);

        return R.ok().data("teacher", teacher).data("courseList", courseList);
    }


}

